/**
 * 开始界面
 * 如果有与现有不一样的需求自己拓展实现
 */

import GameCtr from "../../Controller/GameCtr";
import AudioManager from "../../Common/AudioManager";
import GameData from "../../Common/GameData";
import vv from "../../Common/vv";
import GameDataInstance from "../../Common/GameDataInstance";
import SoundManager from "../../Common/SoundManager";
import { PlayerStorage } from "../../Common/PlayerStorageManager";


const { ccclass, property } = cc._decorator;

@ccclass
export default class Start extends cc.Component {

    @property(cc.Node)
    ndStart: cc.Node = null;
    @property(cc.Node)
    ndShareTip: cc.Node = null;

    @property(cc.Node)
    ndmaxsocre: cc.Node = null;//

    @property(cc.Label)
    ndtip: cc.Label = null;


    //开始tip
    @property(cc.Node)
    playtip:cc.Node = null


    //声音打开
    @property(cc.Node)
    voiceon:cc.Node = null

    //声音关闭
    @property(cc.Node)
    voicoff:cc.Node = null


    //排行榜
    @property(cc.Node)
    rankingView:cc.Node = null

    @property(cc.Sprite)
    cpr:cc.Sprite = null


    //分享
    @property(cc.Node)
    share:cc.Node = null
    // LIFE-CYCLE CALLBACKS:
    isMusic = false;
    onLoad() {
       
    }

    start() {
        cc.loader.load("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1547643234501&di=c5120af326f5ee12a92678cf8b4805a0&imgtype=0&src=http%3A%2F%2Fpic1.nipic.com%2F2008-12-30%2F200812308231244_2.jpg",function(err,texture)
        {
            console.log('hahah')
           let frame = new cc.SpriteFrame(texture)
           this.cpr.SpriteFrame = frame
        })

      if(GameDataInstance.Instance.bannerAd!=null)
      {
        GameDataInstance.Instance.bannerAd.show()
        .then((res) => {
            console.log('广告显示成功',res);
        })
        .catch(err => {
            console.log('广告组件出现问题', err);
        })
      }

        this.voiceon.on('touchend',()=>
        {
            console.log('声音点击')
            GameDataInstance.Instance.voiceon = false
            this.voiceon.active = false
            this.voicoff.active = true
        })
      

          this.voicoff.on('touchend',()=>
        {
            console.log('声音点击')
            GameDataInstance.Instance.voiceon = true
            this.voiceon.active = true
            this.voicoff.active = false
        })

       // vv.share()
        GameData.level = 0
        GameCtr.exp = 0
        GameCtr.score = 0

        console.log('转发title',GameDataInstance.Instance.titie)
        console.log('转发图片',GameDataInstance.Instance.thumb)
        vv.btnClick(this.share,()=>
        {
            tt.shareAppMessage({
                title: GameDataInstance.Instance.titie,
                //desc:'这是文案？？？？？？',
                imageUrl:GameDataInstance.Instance.thumb
              })
        })

        if(GameDataInstance.Instance.voiceon)
        {
            this.voiceon.active = true
            this.voicoff.active = false
        }
        else
        {
            this.voiceon.active = false
            this.voicoff.active = true
        }


       

        let action1 = cc.scaleTo(1,1.2,1.2)
        let action2 = cc.scaleTo(1,1,1)

        let action = cc.repeatForever(cc.sequence(action1,action2))

        this.playtip.runAction(action)



        let maxscore = cc.sys.localStorage.getItem('maxscore')

        if(maxscore!=null)
        {
            if( GameDataInstance.Instance.MaxScore <=maxscore)
            {
                GameDataInstance.Instance.MaxScore = maxscore
            }
        }

        this.ndmaxsocre.getComponent(cc.RichText).string = (Math.floor(GameDataInstance.Instance.MaxScore)).toString()

        this.ndStart.on('touchend',()=>
        {
            cc.director.loadScene('fkxxl')
        })


        // this.rankingView.on('touchend',()=>
        // {

        //     if(GameDataInstance.Instance.openid.length<10)
        //     {
        //         vv.showTip('需要先登录头条账号才能查看排行榜哦！')
        //     }

        //     else
        //     {
        //         vv.openPrefab('Lgpaihang',(node)=>
        //         {
        //             // GameDataInstance.Instance.myworldpaihangdata = res.data.my
        //             // console.log('我的世界排行',GameDataInstance.Instance.myworldpaihangdata )
        //             // GameDataInstance.Instance.worldpaihangdata = res.data.list
        //             // console.log('世界排行',GameDataInstance.Instance.worldpaihangdata)
        //             let rankingnode = node.getComponent('LGRankingview').requestui(GameDataInstance.Instance.worldpaihangdata)
                  
        //         })
        //         vv.sendPostHttpRequest('https://sjh5.88youxi.cn/app/index.php?i=55&c=entry&do=paihangbang&m=wxs_api',{'city':0,'openid':GameDataInstance.Instance.openid,'page_size':20,'page':1,'type':1},(res)=>
        //         {
        //             console.log('排行榜',res)
        //             console.log('data',res.data.list)
                   
        //        })

                 
        //        vv.sendPostHttpRequest('https://sjh5.88youxi.cn/app/index.php?i=55&c=entry&do=paihangbang&m=wxs_api',{'city':'合肥','openid':GameDataInstance.Instance.openid,'page_size':20,'page':1,'type':1},(res)=>
        //        {
        //               GameDataInstance.Instance.mylocalpaihangdata = res.data.my
        //               console.log('我的本地排行', GameDataInstance.Instance.mylocalpaihangdata)
        //               GameDataInstance.Instance.localpaihangdata = res.data.list
        //               console.log('本地排行',GameDataInstance.Instance.localpaihangdata)
        //        })
            
        //     }
          
        // })
    }

    // //开始游戏
    // startGame() {
    //     GameCtr.startGame();
    // }
    // aaaa() {
    //     GameCtr.score = 2001;
    //     GameCtr.sendScore();
    // }

    update(dt) {

    }
}
